package com.oa.modules.approvalsec1.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.oa.common.utils.AppUtils;
import com.oa.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.oa.modules.approvalsec1.entity.UserBankEntity;
import com.oa.modules.approvalsec1.service.UserBankService;
import com.oa.common.utils.R;



/**
 * 银行开户
 *
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-08-16 14:54:43
 */
@RestController
@RequestMapping("user/bank")
@Api(tags = "银行开户相关接口")
public class UserBankController extends AbstractController {
    @Autowired
    private UserBankService userBankService;


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") String id){
		UserBankEntity userBank = userBankService.getById(id);
        return R.ok().put("userBank", userBank);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public R save(@RequestBody UserBankEntity userBank){
        userBank.setId(AppUtils.getUUID());
		userBankService.save(userBank);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody UserBankEntity userBank){
		userBankService.updateById(userBank);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public R delete(@RequestBody String[] ids){
		userBankService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 发送给银行接收人员的测试通知
     */
    @PostMapping("/pushBankTest")
    @ApiOperation(value = "发送给银行接收人员的测试通知")
    public R pushBankTest(@RequestParam Map<String, Object> params){
        if(params != null && params.get("bankName") != null){
            List<UserBankEntity> userBankList = userBankService.getByLikeBankName(params.get("bankName").toString());
            for (UserBankEntity userBank: userBankList){
                String response = WxLoginController.OpenAccountPush(userBank.getWxOpenId(),"测试公司", "申请人","11111111111","Code123456789","测试公司地址位置信息");
                System.out.println("response:" + response);
            }
            return R.ok();
        }else if(params != null && params.get("openId") != null){
            String response = WxLoginController.OpenAccountPush(params.get("openId").toString(),"测试公司", "申请人","11111111111","Code123456789","测试公司地址位置信息");
            System.out.println("response:" + response);
            return R.ok();
        }else{
            return R.error("缺失必传参数");
        }
    }
}
